const {
  GiftShopModel
} = require('../../../../utils/giftshop-model.js');
var giftShopModel = new GiftShopModel();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    detail: null, //详情
    serviceOrderCode: null, //服务单号
    orderCode: null, //订单号
    orderStatus: null, //1从订单列表过来
    skuId:null,//商品sku
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      serviceOrderCode: options.serviceOrderCode,
      orderCode: options.orderCode,
      orderStatus: options.orderStatus,
      skuId: options.skuId,
    }, () => {
      this.getServiceOrderDetail(); //服务单详情
    })
  },

  /**
   * 服务单详情
   */
  getServiceOrderDetail() {
    let param = {
      merchantId: wx.getStorageSync('merchantId'), //商户ID
    }
    if (this.data.orderStatus == 1) {
      param.orderCode = this.data.orderCode //订单号
      param.skuId=this.data.skuId
    } else {
      param.serviceOrderCode = this.data.serviceOrderCode //服务单号
    }
    giftShopModel.serviceOrderDetail(param).then(data => {
      this.setData({
        detail: data,
      })
    }).catch(err => {
      wx.showToast({
        title: `${err.error}`,
        icon: 'none',
        duration: 2000
      })
    })
  },

  /**
   * 复制
   */
  setCopyCode: function (e) {
    let code = e.currentTarget.dataset.code //服务单号
    wx.setClipboardData({
      data: code,
      success(res) {
        wx.getClipboardData({
          success(res) {}
        })
      }
    })
  },

  /**
   * 售后进度
   */
  salesProgress:function(){
    wx.navigateTo({
      url: `/pages/giftShop/serviceOrder/serviceProgress/index?serviceOrderCode=${this.data.serviceOrderCode}`
    })
  },

    /**
   * 取消换货
   */
  cancelService(e) {
    wx.reportAnalytics('gift_service_cancelapply');
    let that = this;
    wx.showModal({
      title: '是否取消售后申请？',
      cancelColor: '#333333', //取消文字的颜色
      confirmColor: '#333333', //确定文字的颜色
      confirmText: '确认',
      success(res) {
        if (res.confirm) {
          giftShopModel.serviceOrderCancel({
            merchantId: wx.getStorageSync('merchantId'), //商户ID
            serviceOrderCode: that.data.serviceOrderCode, //服务单号
          }).then(data => {
            that.setData({
              serviceData: [], //申请
              isHints: false,
              pageCount: 0,
              pageIndex: 1,
              pageCount: 0,
              loadText: "",
            }, () => {
              that.getServiceOrderDetail();
            })
          }).catch(err => {
            wx.showToast({
              title: `${err.error}`,
              icon: 'none',
              duration: 2000
            })
          })
        } else if (res.cancel) {}
      }
    })
  },
})